/**
 * 单元测试
 *
 * @author bian
 * @createDate 2018.3.1
 */

var common = require("./common");

// auto define common variable
var evalString = "";
Object.keys(common).forEach((e,i) => {
    evalString += `var ${e} = common.${e};`;
});
if(typeof(evalString) !== "undefined" || evalString !== null){
    eval(evalString);
}


var co = require("co");

var appid = "wx2a51c89f0856c17e";
var appsecret = "f4fe1ff67a27d4d618d63353917e1e4d";

function *addButton(){
    var res = yield request
        .get(`https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${appsecret}`);
    var data = JSON.parse(res.text);
    var access_token = data.access_token;
    res = yield request
        .post(`https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${access_token}`)
        .send({
            "button" : [
                {
                    "type":"view",
                    "name":"一键连WIFI",
                    "url":"http://xueban3.oureda.cn:8080/smartconfig"
                },
            ]
        });
    // res = yield request.get(`https://api.weixin.qq.com/cgi-bin/menu/get?access_token=${access_token}`);
    // console.log(res.text);
// https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
}
co(function*(){
    yield addButton();
}).catch(function(err){
    console.log(err);
});

